<script>
    $.extend($.fn.validatebox.defaults.rules, {
        percentunique: {
            validator: function (value, param) {
                var success;
                $.ajax({
                    cache: false,
                    async: false,
                    type: 'POST',
                    url: '${contextPath}/security/hdw/exchange_amount_money_divide_detail/unique.htm',
                    data: {
                        percent: value,
                        amount: (param[0] || ''),
                        divideId: (param[1] || ''),
                        id: (param[2] || '')
                    },
                    dataType: 'json',
                    success: function (json) {
                    <@app.json_jump/>
                        if (json.success) {
                            success = true;
                        } else {
                            success = false;
                        }
                    }
                });

                return success;
            },
            message: "同一换电次数分配比例最大为100%"
        }
    });
    $(function () {
        $('#page_table_detail_${pid}').datagrid({
            fit: true,
            width: '100%',
            height: '100%',
            striped: true,
            pagination: true,
            url: "${contextPath}/security/hdw/exchange_amount_money_divide_detail/page.htm?divideId=${id}",
            fitColumns: true,
            pageSize: 10,
            pageList: [10, 50, 100],
            idField: 'id',
            singleSelect: true,
            selectOnCheck: false,
            checkOnSelect: false,
            autoRowHeight: false,
            rowStyler: gridRowStyler,
            columns: [
                [
                    {
                        title: '换电次数',
                        align: 'center',
                        field: 'amount',
                        width: 40
                    },
                    {
                        title: '机构类型',
                        align: 'center',
                        field: 'orgTypeName',
                        width: 40
                    },
                    {
                        title: '机构',
                        align: 'center',
                        field: 'orgIdName',
                        width: 40
                    },
                    {
                        title: '分配比例',
                        align: 'center',
                        field: 'percent',
                        width: 40,
                        formatter: function (val, row) {
                            return row.percent + "%"
                        }
                    },
                    {
                        title: '操作',
                        align: 'center',
                        field: 'id',
                        width: 50,
                        formatter: function (val, row) {
                            var html = '';
                        <@app.has_oper oper_code='6_7_3'>
                            html += ' <a href="javascript:edit_detail(ID)">修改</a>'
                        </@app.has_oper>
                        <@app.has_oper oper_code='6_7_4'>
                            html += ' <a href="javascript:remove_detail(ID)">删除</a>'
                        </@app.has_oper>
                            return html.replace(/ID/g, row.id);
                        }
                    }
                ]
            ],
            onLoadSuccess: function () {
                $('#page_table_detail_${pid}').datagrid('clearChecked');
                $('#page_table_detail_${pid}').datagrid('clearSelections');
            }
        });
        var ok = function () {
            return true;
        }
        $('#${pid}').data('ok', ok);
    })

    function reload_detail() {
        $('#page_table_detail_${pid}').datagrid('reload');
    }

    function add_detail() {
        App.dialog.show({
            css: 'width:320px;height:280px;',
            title: '新建',
            href: "${contextPath}/security/hdw/exchange_amount_money_divide_detail/add.htm?divideId=${id}",
            event: {
                onClose: function () {
                    reload_detail();
                }
            }
        });
    }
    function remove_detail(id) {
        $.messager.confirm('提示信息', '确认删除?', function (ok) {
            if (ok) {
                $.post("${contextPath}/security/hdw/exchange_amount_money_divide_detail/delete.htm?id=" + id, function (json) {
                    if (json.success == 1) {
                        $.messager.alert('提示消息', '操作成功', 'info');
                        reload_detail();
                    } else {
                        $.messager.alert('提示消息', json.message, 'info');
                    }
                }, 'json');
            }
        });
    }
    function edit_detail(id) {
        App.dialog.show({
            css: 'width:320px;height:280px;',
            title: '修改',
            href: "${contextPath}/security/hdw/exchange_amount_money_divide_detail/edit.htm?id=" + id,
            event: {
                onClose: function () {
                    reload_detail();
                }
            }
        });
    }
</script>
<div class="tab_item" style="display: block">
    <div class="toolbar clearfix">
        <div class="float_right">
        <@app.has_oper oper_code='6_7_2'>
            <button class="btn btn_red add" onclick="add_detail()">新建</button>
        </@app.has_oper>
        </div>
        <h3>分配明细</h3>
    </div>
    <div class="grid" style="height:345px;">
        <table id="page_table_detail_${pid}"></table>
    </div>
</div>
